package com.java.dao;

import com.java.dao.impl.baseDao;
import com.java.doMain.commodity;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Author xyd
 * @Date 2021/12/22 20:28
 * @Version 1.0
 */
public class commDaoImpl extends baseDao implements commDao {
    @Override
    public List<commodity> selectByType(String cType,Integer currentPage) {
        int i = (currentPage-1)*4;
        String sql = "select * from commodity where ctype=? limit ?,4";
        return queryForList(commodity.class,sql,cType,i);
    }

    @Override
    public Integer selectByAll(String cType) {
        String sql = "select count(*) from commodity where cType = ?";
        Number o = (Number) queryForSingleValue(sql,cType);
        return o.intValue();
    }

    @Override
    public List<commodity> selectAll() {
        String sql = "select * from commodity";
        return queryForList(commodity.class,sql);
    }



    @Override
    public int updateComm(int cID, String cName, int cPrice, int cInventory, String cType, String cmessage, String cStyle) {
        String sql = "update commodity set cname=?,cprice=?,cinventory=?,ctype=?,cmessage=?,cstyle=?where cid=?";
        return update(sql,cName,cPrice,cInventory,cType,cmessage,cStyle,cID);
    }

    @Override
    public int insertComm(String cName, int cPrice, int cInventory, String cType, String cmessage, String cStyle) {
        String sql = "insert into commodity (cname,cprice,cinventory,ctype,cmessage,cstyle) values (?,?,?,?,?,?)";
        return update(sql,cName,cPrice,cInventory,cType,cmessage,cStyle);
    }

    @Override
    public int delComm(Integer cid) {
        String sql = "delete from commodity where cid=?";
        return update(sql,cid);
    }

    @Override
    public int updateCommisshow(int cID) {
        String sql = "update commodity set isshow=1 where cid=?";
        return update(sql,cID);
    }

    @Override
    public commodity selectByCid(Integer cid) {
        String sql = "select * from commodity where cID = ?";
        return queryForOne(commodity.class,sql,cid);
    }

    @Test
    public void te(){


        Set s = new HashSet();
        System.out.println(s);

    }
}
